/**
 * Created by zhangqin on 2017/4/21.
 */
$(function () {
    var dataWeixin = {
        head:{},
        body: {
            url: encodeURIComponent(window.location.href)
        }
    }
    var d = JSON.stringify(dataWeixin);
    $.ajax({
        url : getHost()+"/api/store/wx/jspai?msg=" + d,
        type:"post",
        async :false,
        success: function (data) {
            var body= data.body;
         //   alert(JSON.stringify(body))
            wx.config({
                debug: false,
                appId: body.appId,
                timestamp: body.timestamp,
                nonceStr: body.nonceStr,
                signature: body.signature,
                jsApiList: [
                    'checkJsApi',
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'onMenuShareQZone'
                ]
            });
            console.log("加载配置成功----------------------------"+JSON.stringify(body));
            wx.ready(function(){
                console.log("微信准备成功----------------------------");
            });
        }
    })
});


function getShareOption() {
    var op = {
        title: pageTitle,
        desc: pageDes,
        link:  encodeURI(window.location.href) ,
        imgUrl: pageImage,
        success: function (res) {
        },
        fail: function (res) {
        }
    }
    return op;
}

function setWxEvent() {
var option = getShareOption();
    wx.onMenuShareAppMessage(option);

    wx.onMenuShareTimeline(option);

    wx.onMenuShareQQ(option);

    wx.onMenuShareWeibo(option);

    wx.onMenuShareQZone(option);
    console.log("设置分享成功----------------------------");
}

wx.error(function (res) {
   // alert(JSON.stringify(res))
});